'use strict';

const {
  getDefaultModelConfig
} = require("../../utils/common");

module.exports = app => {
  const { STRING, BIGINT, INTEGER, TINYINT } = app.Sequelize;

  return app.model.define('SystemMenu', {
    id: {
      type: BIGINT,
      primaryKey: true,
      autoIncrement: true,
      comment: '菜单ID'
    },
    name: {
      type: STRING(50),
      allowNull: false,
      comment: '菜单名称'
    },
    permission: {
      type: STRING(100),
      allowNull: false,
      defaultValue: '',
      comment: '权限标识'
    },
    type: {
      type: INTEGER,
      allowNull: false,
      comment: '菜单类型'
    },
    sort: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '显示顺序'
    },
    parentId: {
      type: BIGINT,
      allowNull: false,
      defaultValue: 0,
      field: 'parent_id',
      comment: '父菜单ID'
    },
    path: {
      type: STRING(200),
      allowNull: true,
      defaultValue: '',
      comment: '路由地址'
    },
    icon: {
      type: STRING(100),
      allowNull: true,
      defaultValue: '#',
      comment: '菜单图标'
    },
    component: {
      type: STRING(255),
      allowNull: true,
      comment: '组件路径'
    },
    componentName: {
      type: STRING(255),
      allowNull: true,
      field: 'component_name',
      comment: '组件名'
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '菜单状态'
    },
    visible: {
      type: TINYINT,
      allowNull: true,
      defaultValue: 1,
      comment: '是否可见'
    },
    keepAlive: {
      type: TINYINT,
      allowNull: true,
      defaultValue: 1,
      field: 'keep_alive',
      comment: '是否缓存'
    },
    alwaysShow: {
      type: TINYINT,
      allowNull: true,
      defaultValue: 1,
      field: 'always_show',
      comment: '是否总是显示'
    },
    ...getDefaultModelConfig(app)
  }, {
    tableName: 'system_menu',
    timestamps: false, // 不使用Sequelize的默认时间戳字段
  });
};
